package com.robert.jfinal.config;

import com.jfinal.config.*;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.robert.jfinal.controller.MemberController;
import com.robert.jfinal.model.Member;

/**
 * Created by zhenghao on 2016/3/22.
 */
public class DemoConfig extends JFinalConfig {
    @Override
    public void configConstant(Constants me) {

        //开启debug 模式
        me.setDevMode(true);

    }

    @Override
    public void configRoute(Routes me) {

        //配置映射关系
        me.add("/member", MemberController.class);

    }

    @Override
    public void configPlugin(Plugins me) {

        //配置连接池
        C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://172.16.9.22:3306/test", "kaifa_user", "123456");
        me.add(cp);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
        me.add(arp);

        //配置数据表映射关系。默认主键 id
        arp.addMapping("member", Member.class);

    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {

        //设置项目根路径
        me.add(new ContextPathHandler("root"));

    }
}
